package ubiqweb.spring3.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;


import ubiqweb.spring3.model.Attendees;
import ubiqweb.spring3.service.AttendeesService;

@Controller
@RequestMapping("/reports")
public class AttendeesController {

	@Autowired
	private AttendeesService attendeesService;
	
	@RequestMapping(value = "/attendeesList" ,method = RequestMethod.GET)
	public ModelAndView listAttendees(HttpSession session, HttpServletRequest request) {
		String trainingId = request.getParameter("trainingId");
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("attendees",  attendeesService.listAttendees(trainingId));
		return new ModelAndView("reports", model);
	}
	
	@RequestMapping(value = "/myTrainings", method = RequestMethod.GET)
	public ModelAndView listMyTrainings(HttpSession session, HttpServletRequest request) {
		String userId = session.getAttribute("sessionUsrID").toString();
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("attendees", attendeesService.listMyTrainings(userId));
		return new ModelAndView("reports", model);
	}
	
}